package com.cskaoyan.user.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.mall.commons.util.CookieUtil;
import com.cskaoyan.user.service.ILoginService;
import org.hibernate.validator.internal.engine.messageinterpolation.parser.TokenIterator;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Enumeration;

/**
 * @author: erdonc
 * @date: 2022/9/22 10:15
 * TODO: 用户退出账号
 */
@RestController
public class LoginOutController {


    /**
     * @Author: erdonc
     * @date : 2022/9/22 10:22
     * TODO: 用户退出账号
     */
    @GetMapping("user/loginOut")
    public ResponseData loginOut(HttpServletRequest request, HttpServletResponse response) {
        // 退出登录时，删除cookie中的access_token

        Cookie cookie = CookieUtil.genCookie("access_token", null, "/", 0);
        response.addCookie(cookie);

        System.out.println(request.getAttribute("user_info"));
        System.out.println(cookie.getName());
        System.out.println(cookie.getValue());

        // request.removeAttribute("user_info");

        return new ResponseUtil<>().setData(null);
    }

}
